/**  
 * All rights Reserved, Designed By www.tydic.com
 * @Title:  CommonController.java   
 * @Package com.axin.controller   
 * @Description:    TODO(用一句话描述该文件做什么)   
 * @author: axin     
 * @date:   2019年3月10日 下午2:47:50   
 * @version V1.0 
 * @Copyright: 2019 www.hao456.top Inc. All rights reserved. 
 */
package com.axin.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.axin.common.entity.ApiToken;
import com.axin.common.entity.DataGridResult;
import com.axin.common.entity.JsonResult;
import com.axin.common.entity.PageObject;
import com.axin.common.exception.UnTokenException;
import com.axin.entity.HbSymbols;
import com.axin.service.CommonService;

/**   
 * @Description: 基础信息 
 * @ClassName:  CommonController
 * @author:  Axin 
 * @date:   2019年3月10日 下午2:47:50   
 * @Copyright: 2019 www.hao456.top Inc. All rights reserved. 
 */

@Controller
@RequestMapping("common")
public class CommonController {
	
	
	@Autowired
	private CommonService commonService;
	
	@Value("${ACCESS_KEY_ID}")
	private String ACCESS_KEY_ID;
	@Value("${ACCESS_KEY_SECRET}")
	private String ACCESS_KEY_SECRET;
	@Value("${ACCESS_PASSWORD}")
	private String ACCESS_PASSWORD;
	
	
	
	
	
	/**
	 * 
	 * @Description: 导出火币网的交易对到本地数据库  
	 * @Title: importRemoteSymbols   
	 * @return: JsonResult      
	 * @throws
	 */
	@RequestMapping("importRemoteSymbols")
	@ResponseBody
	public JsonResult importRemoteSymbols(HttpServletRequest request){
		ApiToken token = (ApiToken)request.getAttribute("apiToken");
		if(token == null){
			return new JsonResult(new UnTokenException("您尚未设置密钥，不能处理您的请求！"));
		}
		return commonService.importRemoteSymbols(token);
		
	}
	
	
	/**
	 * 
	 * @Description: 导入火币网的币别到本地数据库
	 * @Title: importRemoteCurrencys   
	 * @return: JsonResult      
	 * @throws
	 */
	@RequestMapping("importRemoteCurrencys")
	@ResponseBody
	public JsonResult importRemoteCurrencys(HttpServletRequest request){
		ApiToken token = (ApiToken)request.getAttribute("apiToken");
		if(token == null){
			return new JsonResult(new UnTokenException("您尚未设置密钥，不能处理您的请求！"));
		}
		return commonService.importRemoteCurrencys(token);
		
	}
	
	
	@RequestMapping("getSymbols")
	@ResponseBody
	public DataGridResult getSymbols(PageObject page, HttpServletRequest request){
		ApiToken token = (ApiToken)request.getAttribute("apiToken");
		if(token == null){
			return null;
		}
		DataGridResult result = commonService.getSymbols(token,page);
		return result;
	}
	
	@RequestMapping("getLocalSymbols")
	@ResponseBody
	public DataGridResult getLocalSymbols(HbSymbols symbols,PageObject page){
		/*HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
		HttpSession session = request.getSession();
		HbUser user =(HbUser)session.getAttribute("user");*/
		DataGridResult result = commonService.selectLocalSymbols(symbols, page);
		return result;
	}
	
	@RequestMapping("getLocalAllSymbols")
	@ResponseBody
	public List<HbSymbols> getLocalAllSymbols(){
		return commonService.selectLocalSymbols();
	}
	
	
	@RequestMapping("getLocalSymbolsByParam")
	@ResponseBody
	public List<HbSymbols> getLocalSymbolsByParam(String q){
		return commonService.selectLocalSymbolsByLikeSymbol(q);
	}
	
	
	@RequestMapping("getCurrencys")
	@ResponseBody
	public DataGridResult getCurrencys(PageObject page, HttpServletRequest request){
		ApiToken token = (ApiToken)request.getAttribute("apiToken");
		if(token == null){
			return null;
		}
		DataGridResult result = commonService.getCurrencys(token,page);
		return result;
	}
	
	
	@RequestMapping("getLocalCurrencys")
	@ResponseBody
	public DataGridResult getLocalCurrencys(String name, PageObject page){
		DataGridResult result = commonService.selectLocalCurrencys(name, page);
		return result;
	}

}
